package com.jcp.daoimp;

import java.util.List;

import com.jcp.dao.PostDao;
import com.jcp.entity.Posts;
import com.jcp.util.DBUtil;
/**
 * 岗位管理的dao实现类
 * @author 朱耿封
 *
 */
public class PosImple implements PostDao {
	/**
	 * 岗位管理的查询
	 * @param strLike：模糊查询的字段
	 * @return Posts的集合
	 */
	@Override
	public List<Posts> posSel(String strLike) {
		String sql = "select p.posId,p.posName,count(u.posId) as posNum,p.posWork from posts p left join users u ON u.posId=p.posId where posName like ? GROUP BY p.posId ";
		List<Posts> post = DBUtil.exQuery(sql, Posts.class, "%"+strLike+"%");
		return post;
	}
	/**
	 * 岗位管理的增加
	 * 参数 ：岗位的实体类：post
	 * 返回值:post的实体类
	 */
	@Override
	public boolean posAdd(Posts post) {
		String sql = "insert into posts(posName,posWork)values(?,?)";
		
		return DBUtil.exUpdate(sql, post.getPosName(),post.getPosWork())>0;
	}
	//岗位表的修改功能
	@Override
	public boolean posUpdate(Posts post) {
		String sql = "update posts set posName=?,posWork=? where posId=? ";
		int dept = DBUtil.exUpdate(sql, post.getPosName(),post.getPosWork(),post.getPosId());
		return dept>0;
	}
	//岗位表的删除功能
	@Override
	public boolean posDel(int PostId) {
		String sql = "delete from posts where posId=?";
		int flag = DBUtil.exUpdate(sql, PostId);
		return flag>0;
	}

}
